package top.kaoshanji.p1ch03a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.ByteBuffer;

/**
 * 代码清单 p1ch03a-05：字节缓冲区的压缩操作的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/5 19:53
 */
public class ByteBufferExample03 {

    private static final Logger logger = LogManager.getLogger(ByteBufferExample03.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch03a-05：字节缓冲区的压缩操作的示例...");

        ByteBuffer buffer = ByteBuffer.allocate(32);
        buffer.put(new byte[16]);
        buffer.flip();

        // System.out.println(buffer.getInt());
        buffer.getInt(); // 当前读取位置为 4

        buffer.compact(); // 压缩

        System.out.println(buffer.position());

    }

}
